<!DOCTYPE html>
<html>
    <head>
        <script type="application/javascript" language="javascript" src="jquery-!jquery!.min.js"></script>
        <script type="application/javascript" language="javascript" src="utility-!utility!.min.js"></script>
    </head>
    <body>
        <script>
            $(function () {
                /**
                 * Handles data sent via chrome.extension.sendRequest().
                 * @param request Object Data sent in the request.
                 * @param sender Object Origin of the request.
                 * @param callback Function The method to call when the request completes.
                 */
                function onRequest(request, sender, callback) {
                    $u.log(1, "background.onRequest", request, sender, callback);
                    if (request.action === 'getPage') {
                        $.ajax({
                            url: request.value,
                            error:
                                function (XMLHttpRequest, textStatus, errorThrown) {
                                    $u.error("background.getPage", textStatus);
                                    responseText
                                    callback({
                                        status       : XMLHttpRequest.status,
                                        statusText   : textStatus,
                                        responseText : "",
                                        errorThrown  : errorThrown
                                    });
                                },
                            success:
                                function (data, textStatus, XMLHttpRequest) {
                                    $u.log(1, "background.getPage", textStatus);
                                    callback({
                                        status       : XMLHttpRequest.status,
                                        statusText   : textStatus,
                                        responseText : data,
                                        errorThrown  : ""
                                    });
                                }
                        });
                    }
                };

                // Wire up the listener.
                chrome.extension.onRequest.addListener(onRequest);
                $u.log(1, "Ready");
            }).ready();
        </script>
    </body>
</html>
